﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using ReceiptPrint.Models;


namespace ReceiptPrint.ViewModels.TemplateVMs
{
    public partial class TemplateListVM : BasePagedListVM<Template_View, TemplateSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("Template", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"", dialogWidth: 600),
                this.MakeStandardAction("Template", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "", dialogWidth: 600),
                this.MakeStandardAction("Template", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "", dialogWidth: 600),
                //this.MakeStandardAction("Template", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "", dialogWidth: 600),
                this.MakeAction("Template","ReceiptInfo","商品详情","商品详情", GridActionParameterTypesEnum.SingleId,dialogWidth:500)
                .SetShowInRow(true).SetHideOnToolBar(true),
                //this.MakeAction("Template","Print","打印","打印", GridActionParameterTypesEnum.SingleId,dialogHeight:700,dialogWidth:500)
                //.SetShowInRow(true).SetHideOnToolBar(true),


            };
        }


        protected override IEnumerable<IGridColumn<Template_View>> InitGridHeader()
        {
            return new List<GridColumn<Template_View>>{
                this.MakeGridHeader(x => x.ExcelFileName),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Header),
                this.MakeGridHeader(x => x.SubHeader),
                this.MakeGridHeader(x => x.Footer),
                this.MakeGridHeaderAction(width: 300)
            };
        }

        public override IOrderedQueryable<Template_View> GetSearchQuery()
        {
            var query = DC.Set<Template>().WhereIf(!string.IsNullOrEmpty(Searcher.ExcelFileId),x=>x.ExcelFileId == long.Parse(Searcher.ExcelFileId))
                .CheckContain(Searcher.Name, x => x.Name)
                .Select(x => new Template_View
                {
                    ID = x.ID,
                    Name = x.Name,
                    Header = x.Header,
                    SubHeader = x.SubHeader,
                    Footer = x.Footer,
                    ExcelFileName = x.ExcelFile.Name
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class Template_View : Template
    {
        [Display(Name = "文件名称")]
        public string ExcelFileName { get; set; }
    }
}
